    ' Copyright 2009, 2010 Massimo Franciosa
    'This file is part of MYLK.

    'MYLK is free software; you can redistribute it and/or modify
    'it under the terms of the GNU General Public License as published by
    'the Free Software Foundation; either version 2 of the License, or
    '(at your option) any later version.

    'Nome-Programma is distributed in the hope that it will be useful,
    'but WITHOUT ANY WARRANTY; without even the implied warranty of
    'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    'GNU General Public License for more details.

    'You should have received a copy of the GNU General Public License
    'along with Nome-Programma; if not, write to the Free Software
    'Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

Public Class InnerFramePanel

  Public Enum FramesPart
    NorthWest
    North
    NorthEast
    East
    SouthEast
    South
    SouthWest
    West
  End Enum

  Public Property FrameN() As Image
    Get
      Return pbN.BackgroundImage
    End Get
    Set(ByVal value As Image)
      pbN.BackgroundImage = value
      If value Is Nothing Then Exit Property
      pbN.Height = pbN.BackgroundImage.Height
      pnMain.Top = pbN.Height
      pnMain.Height = pbS.Top - pbN.Height
    End Set
  End Property

  Public Property FrameS() As Image
    Get
      Return pbS.BackgroundImage

    End Get
    Set(ByVal value As Image)
      pbS.BackgroundImage = value
      If value Is Nothing Then Exit Property
      pbS.Height = pbS.BackgroundImage.Height
      pbS.Top = Me.Height - pbS.Height
      pnMain.Height = pbS.Top - pbN.Height
    End Set
  End Property

  Public Property FrameW() As Image
    Get
      Return pbW.BackgroundImage
    End Get
    Set(ByVal value As Image)
      pbW.BackgroundImage = value
      If value Is Nothing Then Exit Property
      pbW.Width = pbW.BackgroundImage.Width
      pnMain.Left = pbW.Width
    End Set
  End Property

  Public Property FrameE() As Image
    Get
      Return pbE.BackgroundImage
    End Get
    Set(ByVal value As Image)
      pbE.BackgroundImage = value
      If value Is Nothing Then Exit Property
      pbE.Width = pbE.BackgroundImage.Width
      pbE.Left = Me.Width - pbE.Width
      pnMain.Width = pbE.Left - pbE.Width
    End Set
  End Property

  Public Property FrameNW() As Image
    Get
      Return pbNW.BackgroundImage
    End Get
    Set(ByVal value As Image)
      pbNW.BackgroundImage = value
      If value Is Nothing Then Exit Property
      pbNW.Size = pbNW.BackgroundImage.Size
      AttaccaLatiAdAngoli()
    End Set
  End Property

  Public Property FrameNE() As Image
    Get
      Return pbNE.BackgroundImage
    End Get
    Set(ByVal value As Image)
      pbNE.BackgroundImage = value
      If value Is Nothing Then Exit Property
      pbNE.Size = pbNE.BackgroundImage.Size
      pbNE.Left = Me.Width - pbNE.Width
      AttaccaLatiAdAngoli()
    End Set
  End Property

  Public Property FrameSW() As Image
    Get
      Return pbSW.BackgroundImage
    End Get
    Set(ByVal value As Image)
      pbSW.BackgroundImage = value
      If value Is Nothing Then Exit Property
      pbSW.Size = pbSW.BackgroundImage.Size
      pbSW.Top = Me.Height - pbSW.Height
      AttaccaLatiAdAngoli()
    End Set
  End Property

  Public Property FrameSE() As Image
    Get
      Return pbSE.BackgroundImage
    End Get
    Set(ByVal value As Image)
      pbSE.BackgroundImage = value
      If value Is Nothing Then Exit Property
      pbSE.Size = pbSE.BackgroundImage.Size
      pbSE.Top = Me.Height - pbSE.Height
      pbSE.Left = Me.Width - pbSE.Width
      AttaccaLatiAdAngoli()
    End Set
  End Property

  Public ReadOnly Property InnerPanel() As Panel
    Get
      Return pnMain
    End Get
  End Property

  Public Property InnerPanelBackColor() As Color
    Get
      Return pnMain.BackColor
    End Get
    Set(ByVal value As Color)
      pnMain.BackColor = value
    End Set
  End Property

  Private Sub AttaccaLatiAdAngoli()

    Try

      'pannello nord 
      pbN.Left = pbNW.Width
      pbN.Width = Me.Width - pbNE.Width - pbNW.Width

      'pannello ovest
      pbW.Top = pbNW.Height
      pbW.Height = Me.Height - pbSW.Height - pbNW.Height

      'pannello sud 
      pbS.Left = pbSW.Width
      pbS.Width = Me.Width - pbSE.Width - pbSW.Width

      'pannello est
      pbE.Top = pbNE.Height
      pbE.Height = Me.Height - pbSE.Height - pbNE.Height

    Catch ex As Exception
      Throw ex
    End Try

  End Sub


  Public Sub InvertPicturesForFrame(ByVal nFrom As FramesPart, ByVal nTo As FramesPart, ByVal nRotation As RotateFlipType)

    Dim imgFrom, imgTo As Image

    Try

      Select Case nFrom
        Case FramesPart.East
          imgFrom = pbE.BackgroundImage
        Case FramesPart.North
          imgFrom = pbN.BackgroundImage
        Case FramesPart.NorthEast
          imgFrom = pbNE.BackgroundImage
        Case FramesPart.NorthWest
          imgFrom = pbNW.BackgroundImage
        Case FramesPart.South
          imgFrom = pbS.BackgroundImage
        Case FramesPart.SouthEast
          imgFrom = pbSE.BackgroundImage
        Case FramesPart.SouthWest
          imgFrom = pbSW.BackgroundImage
        Case FramesPart.West
          imgFrom = pbW.BackgroundImage
      End Select

      If imgFrom Is Nothing Then Exit Sub

      imgTo = Nothing
      imgTo = imgFrom.Clone
      imgTo.RotateFlip(nRotation)

      Select Case nTo
        Case FramesPart.East
          Me.FrameE = imgTo
        Case FramesPart.North
          Me.FrameN = imgTo
        Case FramesPart.NorthEast
          Me.FrameNE = imgTo
        Case FramesPart.NorthWest
          Me.FrameNW = imgTo
        Case FramesPart.South
          Me.FrameS = imgTo
        Case FramesPart.SouthEast
          Me.FrameSE = imgTo
        Case FramesPart.SouthWest
          Me.FrameSW = imgTo
        Case FramesPart.West
          Me.FrameW = imgTo
      End Select

    Catch ex As Exception
      Throw ex
    End Try
  End Sub

  Public Sub New()

    ' Chiamata richiesta da Progettazione Windows Form.
    InitializeComponent()

    ' Aggiungere le eventuali istruzioni di inizializzazione dopo la chiamata a InitializeComponent().
        Me.DoubleBuffered = True
  End Sub
End Class
